<?php

namespace App\Admin\Controllers\manager;

use App\Admin\Repositories\AdminManagerType;
use App\Models\UsersDonationRecord;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class FlowingController extends AdminController
{
    protected $title = "流水";

    protected $translation = 'admin-manager-flowing';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(UsersDonationRecord::with(['users','manager']), function (Grid $grid) {
            $grid->column('id', '序号');
            $grid->column('users.avatar', '用户头像')
                ->display(function () {
                    // 获取关联用户模型的 avatar 字段
                    return $this->users->avatar;
                })
                ->image('', 50, 50); // 显示为图片，宽高100px
            $grid->column('info','订单信息') -> display(
                function(){
                    return <<<HTML
                       <div style="line-height: 1.8; font-size: 14px; text-align: left;">
                            <div><strong>订单号：</strong> {$this->order_id}</div>
                            <div><strong>捐赠人：</strong> {$this->users->name}/{$this->users->phone}</div>
                            <div><strong>捐赠项目：</strong> {$this->manager->title}</div>
                            <div><strong>捐赠金额：</strong> {$this->amount}</div>

                        </div>
                    HTML;
                }
            );
            $grid->column('project_id','支付信息')->display(
                function (){
                    return <<<HTML
                       <div style="line-height: 1.8; font-size: 14px; text-align: left;">
                            <div><strong>支付方式：</strong> {$this->payment_method}</div>
                            <div><strong>收款渠道：</strong> {$this->payment_method}</div>
                            <div><strong>募款平台：</strong> 数文通</div>
                        </div>
                    HTML;
                }
            );
            $grid->column('order_id', '捐赠说明')->display(
                function (){
                    return <<<HTML
                       <div style="line-height: 1.8; font-size: 14px; text-align: left;">
                            <div><strong>捐赠时间：</strong> {$this->donated_at}</div>
                            <div><strong>捐赠说明：</strong> {$this->describe}</div>
                        </div>
                    HTML;
                }
            );
            $grid->column('receipt_needed', '发票状态')
                ->display(function ($value) {
                    if ($value == 1) {
                        return <<<HTML
<span class="label label-success" style="cursor:pointer; padding: 5px 10px;color: #0a0a0a" title="已开发票">
    已开发票
</span>
HTML;
                    } else {
                        return <<<HTML
<span class="label label-danger" style="cursor:pointer; padding: 5px 10px;color: #0a0a0a" title="尚未开票">
     尚未开票
</span>
HTML;
                    }
                });

            // 订单时间
            $grid->column('created_at', '下单时间')
                ->display(function ($date) {
                    return date('Y-m-d H:i', strtotime($date));
                })
                ->sortable();

        });
    }

}
